package org.csmzxy.class2333;
//外部类
class Calculator {
    //对操作数进行加减法计算
    public void performCalculation(int num1, int num2, char operation) {
        //局部内部类，用于表示计算器
        class OperationCalculator {
            public int add() {
                return num1 + num2;
            }
            public int subtract() {
                return num1 - num2;
            }
        }
        //创建局部内部类的对象
        OperationCalculator calculator = new OperationCalculator();
        if (operation=='+') {
            //在方法内部访问局部内部类的成员
            System.out.println("计算结果: " + calculator.add());
        } else if (operation=='-') {
            System.out.println("计算结果: " + calculator.subtract());
        } else {
            System.out.println("发生错误!");
        }
    }
}
public class example17 {
    public static void main(String[] args) {
        Calculator calculator = new Calculator();
        calculator.performCalculation(5, 3, '+');
    }
}
